package src

import (
	"fmt"
	"math/big"
)

const (
	M = 100
)

type (
	u64s []*big.Int
)

var (
	garrs []u64s
)

func (c *u64s) show() {
	fmt.Printf("m=%d, n = %d, datas:", M+1-len(*c), len(*c))
	for _, v := range *c {
		fmt.Printf("%+v,", v.String())
	}
	fmt.Println()
}

func (c *u64s) descV(k int, v *big.Int) string {
	return fmt.Sprintf("{%d: %+v}", k, v.String())
}

func (c *u64s) findMod(m *big.Int) int {
	var as []string
	for k, v := range *c {
		if big.NewInt(1).Mod(v, m).Sign() == 0 {
			as = append(as, c.descV(k+1, v))
		}
	}
	if len(as) > 0 {
		fmt.Printf("m=%+v, datas: num=%d, %+v\n", M+1-len(*c), len(as), as)
	}
	return len(as)
}

func StatMod77() {
	genArrs()

	fmt.Println(`-----------------------------------------------------------------`)
	modN := big.NewInt(77)
	var findN int
	for _, v := range garrs {
		findN += v.findMod(modN)
	}
	fmt.Println("\nfind all mod===0 77 nums:", findN)
}

func genArrs() {

	var as0 u64s //first
	for i := 0; i < M; i++ {
		as0 = append(as0, big.NewInt(int64(i+1)))
	}
	garrs = append(garrs, as0)

	for i := 1; i < M; i++ {
		genArr(garrs[i-1]) //next
	}

	for _, v := range garrs {
		v.show()
	}
}

func genArr(vs u64s) {
	var as0 u64s
	for i := 0; i < len(vs)-1; i++ {
		v := new(big.Int)
		v.Add(vs[i], vs[i+1])
		as0 = append(as0, v)
	}
	garrs = append(garrs, as0)
}
